export function setCookie(name, value,expires=1000*60*60*24) {
  var exp = new Date();
  exp.setTime(exp.getTime() + expires);
  document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

export function getCookie(name) {
  var arr,
    reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if ((arr = document.cookie.match(reg))) {
    return unescape(arr[2]);
  } else {
    return null;
  }
}

export function delCookie(name) {
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval = getCookie(name);
  if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

export function init(){
  window.setCookie=setCookie;
  window.getCookie=getCookie;
  window.delCookie=delCookie;
}